package com.question_barrier.service.impl;

import com.question_barrier.entity.BarrierState;
import com.question_barrier.repository.BarrierStateRepository;
import com.question_barrier.result.StateCode;
import com.question_barrier.service.BarrierStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BarrierStateServiceImpl implements BarrierStateService {
    @Autowired
    BarrierStateRepository barrierStateRepository;
   @Override
   public BarrierState findByOpenIdAndGradeAndSubject(String openId, String grade,String subject){
       return  barrierStateRepository.findByOpenIdAndGradeAndSubject(openId, grade, subject);
   }

   @Override
    public boolean existsByOpenIdAndGradeAndSubject(String openId,String grade,String subject){
       return barrierStateRepository.existsByOpenIdAndGradeAndSubject(openId,grade,subject);
   }
    @Override
    public boolean existsByOpenId(String openId){
       return barrierStateRepository.existsByOpenId(openId);
    }
    @Override
    public int updBarrierState(BarrierState barrierState){
       BarrierState barrierStateSave = barrierStateRepository.save(barrierState);
       if(barrierStateSave != null)
           return StateCode.UPDATESUCCESS;
       return StateCode.UPDATEFAIL;
    }
}
